package zhoufu.sz.sanxiao_check.ui.fragment;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;

import java.util.Calendar;

import zhoufu.sz.sanxiao_check.R;

public class DatePickerFragment extends DialogFragment
        implements DatePickerDialog.OnDateSetListener {

    private DatePickerDialog _timePickerDialog;


    @Override
    public DatePickerDialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current time as the default values for the picker
        final Calendar c = Calendar.getInstance();

        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);
        // Create a new instance of TimePickerDialog and return it
        _timePickerDialog = new DatePickerDialog(getActivity(), R.style.DateDialogTheme, this, year, month, day);
        _timePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis()-1000);
        return _timePickerDialog;
    }

    interface TimeProxyListener {
        void onTime(int year, int month, int day);
    }

    TimeProxyListener _timeProxyListener;

    public void setTimeProxyListener(TimeProxyListener timeProxyListener) {
        _timeProxyListener = timeProxyListener;
    }

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        if (_timeProxyListener != null) {
            _timeProxyListener.onTime(year, monthOfYear, dayOfMonth);
        }
    }
}